<?php
/**
* Newsflash Scroller Pro v3.3
* @package Module for Mambo Open Source 4.5.1+
* @copyright (C) by Webraydian.com, MamboToys.com
* All rights reserved
* @link http://mambo.webraydian.com/ <Webraydian.com>
* Mambo toys and tools. 
* Modified Release Date: January 12, 2006
* Original Release Date: Dec. 22, 2004
* @version 3.3
* @license http://creativecommons.org/licenses/by-sa/2.0/
*/

/**
* Restrict direct access to this file.
* @global _VALID_MOS
* 
*/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed. --= MamboToys.com =--' );

    global $my, $mainframe, $_MAMBOTS;

    $blogsc = $mainframe->getBlogSectionCount();
    $bblogcc = $mainframe->getBlogCategoryCount();
    $gbblogsc = $mainframe->getGlobalBlogSectionCount();



    /**
    * This class sets all mammeters, if any.
    * Must first call the MOS function, something like: 
    * $params = mosParseParams( $module->params );
    * and send the $params variable to this class (ns_Scroller)
    * @param $params the results from mosParseParams( $module->params );
    * @example $NS_MAMMETER = new ns_Scroller($params);
    */
    if(!defined('_SCROLLER')) {
        define('_SCROLLER',1);
        class ns_Scroller {

            var $nfsp_version;
            var $if_debug;
            var $nfs_array = array(
                                'SITE' => 'http://mambo.webraydian.com/',
                                'TITLE' => 'Newsflash Scroller Pro (NFSP), &copy; 2004 - 2005',
                                'LINK_TITLE' => 'Download NFSP!',
                                'VER' => '3.3',
                            );

            /**
            * [Mammeter ScrollCount]
            * @var $NS_COUNT
            */
            var $NS_COUNT;

            /**
            * [Mammeter ScrollOwner]
            * @var $NS_OWNER
            */
            var $NS_OWNER;

            /**
            * [Mammeter ScrollBehavior]   // scroll, alternate, slide
            * @var $NS_BEHAVIOR
            */
            var $NS_BEHAVIOR;

            /**
            * [Mammeter ScrollDirection]
            * @var $NS_DIRECTION
            */
            var $NS_DIRECTION;

            /**
            * [Mammeter ScrollHeight]
            * @var $NS_HEIGHT
            */
            var $NS_HEIGHT;

            /**
            * [Mammeter ScrollWidth]
            * @var $NS_WIDTH
            */
            var $NS_WIDTH;

            /**
            * [Mammeter ScrollAmount]
            * @var $NS_AMOUNT
            */
            var $NS_AMOUNT;

            /**
            * [Mammeter ScrollDelay]
            * @var $NS_DELAY
            */
            var $NS_DELAY;

            /**
            * [Mammeter ScrollAlign]
            * @var $NS_ALIGN
            */
            //var $NS_ALIGN;

            /**
            * [Mammeter ScrollSortMethod]  
            * @var $NS_SORT_METHOD
            */
            var $NS_SORT_METHOD; 

            /**
            * [Mammeter ScrollTitles]
            * @var $NS_TITLES
            */
            var $NS_TITLES;

            /**
            * [Mammeter ScrollSpaceChar]
            * @var $NS_SPACE_CHAR
            */
            var $NS_SPACE_CHAR;

            /**
            * [Mammeter ScrollSpaceCharTimes]
            * @var $NS_SPACE_CHAR_TIMES
            */
            var $NS_SPACE_CHAR_TIMES;

            /**
            * [Mammeter ScrollLineChar]
            * @var $NS_LINE_CHAR
            */
            var $NS_LINE_CHAR;

            /**
            * [Mammeter ScrollLineCharTimes]
            * @var $NS_LINE_CHAR_TIMES
            */
            var $NS_LINE_CHAR_TIMES;

            /**
            * [Mammeter ScrollSection]
            * @var $NS_SCROLL_SECTION
            */
            var $NS_SCROLL_SECTION;

            /**
            * [Mammeter ScrollRetainImages]
            * @var $NS_RETAIN_IMAGES
            */
            var $NS_RETAIN_IMAGES;

            /**
            * [Mammeter ScrollImageWidth]
            * @var $NS_IMAGE_WIDTH
            */
            var $NS_IMAGE_WIDTH;

            /**
            * [Mammeter ScrollImageHeight]
            * @var $NS_IMAGE_HEIGHT
            */
            var $NS_IMAGE_HEIGHT;

            /**
            * [Mammeter ScrollUseBGImage]
            * @var $NS_USE_BG_IMAGE
            */
            var $NS_USE_BG_IMAGE;

            /**
            * [Mammeter ScrollBGImage]
            * @var $NS_BG_IMAGE
            */
            var $NS_BG_IMAGE;        

            /**
            * [Mammeter ScrollUseBGImageRepeat]
            * @var $NS_BG_IMAGE_REPEAT
            */
            var $NS_BG_IMAGE_REPEAT;        

            /**
            * [Mammeter ScrollUseBGImageAlign]
            * @var $NS_BG_IMAGE_ALIGN
            */
            var $NS_BG_IMAGE_ALIGN;        

            /**
            * [Mammeter ScrollStripHTML]
            * @var $NS_STRIP_HTML
            */
            var $NS_STRIP_HTML;   



            // CSS override -----------------------
            /**
            * [Mammeter ScrollCSSOverride]
            * @var $NS_CSS_OVERRIDE
            */
            var $NS_CSS_OVERRIDE;

            /**
            * [Mammeter ScrollTextAlign]
            * @var $NS_TEXTALIGN
            */
            var $NS_TEXTALIGN;

            /**
            * [Mammeter ScrollTitleWeight]
            * @var $NS_TITLEWEIGHT
            */
            var $NS_TITLEWEIGHT;

            /**
            * [Mammeter ScrollTitleSize]
            * @var $NS_TITLESIZE
            */
            var $NS_TITLESIZE;

            /**
            * [Mammeter ScrollTitleStyle]
            * @var $NS_TITLESTYLE
            */
            var $NS_TITLESTYLE;

            /**
            * [Mammeter ScrollTextWeight]
            * @var $NS_TEXTWEIGHT
            */
            var $NS_TEXTWEIGHT;

            /**
            * [Mammeter ScrollTextSize]
            * @var $NS_TEXTSIZE
            */
            var $NS_TEXTSIZE;

            /**
            * [Mammeter ScrollTextColor]
            * @var $NS_TEXTCOLOR
            */
            var $NS_TEXTCOLOR;

            /**
            * [Mammeter ScrollBGColor]
            * @var $NS_BG_COLOR
            */
            var $NS_BG_COLOR;

            /**
            * [Mammeter ScrollMargin]
            * @var $NS_MARGIN
            */
            var $NS_MARGIN;

            /**
            * [Mammeter ScrollDetails]
            * @var $NS_DETAILS
            */
            var $NS_DETAILS;

            /**
            * [Mammeter ScrollDetailsTitle]
            * @var $NS_DETAILS_TITLE
            */
            var $NS_DETAILS_TITLE;

            /**
            * [Mammeter ScrollDetailsText]
            * @var $NS_DETAILS_TEXT
            */
            var $NS_DETAILS_TEXT = 0;

            /**
            * [Mammeter ScrollSuffix]
            * @var $NS_SFX
            */
            var $NS_SFX;

            /**
            * [Mammeter ScrollCutoff]
            * @var $NS_CUTOFF
            */
            var $NS_CUTOFF;

            /**
            * [Mammeter ScrollCatSect]
            * @var $NS_CATSECT
            */
            var $NS_CATSECT;  

            /**
            * sort variables used by the returnSortType() function
            * @var $sort_asc
            * @var $sort_desc
            * @var $sort_rand
            */
            var $sort_asc;
            var $sort_desc;
            var $sort_rand;
            var $sort_lpop;
            var $sort_mpop;
            var $sort_newest;
            var $sort_oldest;


            /**
            * set mammeters
            * @var $params returned MOS DB stored key=value mammeter list
            */ 
            function ns_Scroller (&$params) {
                // standard mammeters 
                $this->NS_COUNT              =  @intval($params->get('ScrollCount',            2));  
                $this->NS_SCROLL_SECTION     =  $params->get('ScrollSection');  
                $this->NS_SCROLL_CAT         =  $params->get('ScrollCategory');  
                $this->NS_OWNER              =  @$params->get('ScrollOwner',                   'yes');
                $this->NS_BEHAVIOR           =  @$params->get('ScrollBehavior',                'scroll');
                $this->NS_DIRECTION          =  @$params->get('ScrollDirection',               'up');
                $this->NS_HEIGHT             =  @intval($params->get('ScrollHeight',           140));
                $this->NS_WIDTH              =  @intval($params->get('ScrollWidth',            150));
                $this->NS_AMOUNT             =  @$params->get('ScrollAmount',                  '1');
                $this->NS_DELAY              =  @intval($params->get('ScrollDelay',            65));
                //$this->NS_ALIGN              =  @$params->get('ScrollAlign',                   'center');
                $this->NS_SORT_METHOD        =  @$params->get('ScrollSortMethod',              'random');
                $this->NS_TITLES             =  @$params->get('ScrollTitles',                  'yes');
                $this->NS_SPACE_CHAR         =  @$params->get('ScrollSpaceChar',               '&nbsp;');
                $this->NS_SPACE_CHAR_TIMES   =  @intval($params->get('ScrollSpaceCharTimes',   5));
                $this->NS_LINE_CHAR          =  @$params->get('ScrollLineChar',                '<br />');
                $this->NS_LINE_CHAR_TIMES    =  intval($params->get('ScrollLineCharTimes',     2));
                $this->NS_DETAILS            =  @$params->get('ScrollDetails',                 'no');
                $this->NS_DETAILS_TITLE      =  @$params->get('ScrollDetailsTitle',            'Details');
                $this->NS_SFX                =  @$params->get('ScrollSuffix',                  '');
                $this->NS_CUTOFF             =  @intval($params->get('ScrollCutoff',           0));
                $this->NS_CATSECT            =  @$params->get('ScrollCatSect',                 'cat');
                $this->NS_MARGIN             =  @$params->get('ScrollMargin',                  '4');
                $this->NS_TEXTALIGN          =  @$params->get('ScrollTextAlign',               'left');
                $this->NS_RETAIN_IMAGES      =  @$params->get('ScrollRetainImages',            'yes');
                $this->NS_IMAGE_WIDTH        =  @$params->get('ScrollImageWidth',              '50');
                $this->NS_IMAGE_HEIGHT       =  @$params->get('ScrollImageHeight',             '50');
                $this->NS_USE_BG_IMAGE       =  @$params->get('ScrollUseBGImage',              'no');
                $this->NS_BG_IMAGE           =  @$params->get('ScrollBGImage',                 '');
                $this->NS_BG_IMAGE_REPEAT    =  @$params->get('ScrollUseBGImageRepeat',        'no-repeat');
                $this->NS_BG_IMAGE_ALIGN     =  @$params->get('ScrollUseBGImageAlign',         'top');
                $this->NS_STRIP_HTML         =  @$params->get('ScrollStripHTML',               'yes');



                // CSS mammeters
                $this->NS_CSS_OVERRIDE       =  @$params->get('ScrollCSSOverride',      'no');
                $this->NS_TITLEWEIGHT        =  @$params->get('ScrollTitleWeight',      'normal');
                $this->NS_TEXTWEIGHT         =  @$params->get('ScrollTextWeight',       'normal');
                $this->NS_TITLESTYLE         =  @$params->get('ScrollTitleStyle',       'normal');
                $this->NS_TITLESIZE          =  @$params->get('ScrollTitleSize',        '10');
                $this->NS_TEXTSIZE           =  @$params->get('ScrollTextSize',         '10');
                $this->NS_TEXTCOLOR          =  @$params->get('ScrollTextColor',        '#000000');
                $this->NS_BG_COLOR           =  @$params->get('ScrollBGColor',          'transparent');


                $this->nfsp_version = $this->nfs_array['VER'];
                $this->if_debug     = false;
                $this->sort_asc    = 'oldest';
                $this->sort_desc   = 'newest';
                $this->sort_rand   = 'random';
                $this->sort_lpop   = 'leastpop';
                $this->sort_mpop   = 'mostpop';
                $this->sort_newest = 'newest';
                $this->sort_oldest = 'oldest';
                $this->NS_SCROLL_SECTION = ( $this->NS_CATSECT == 'sect' ? $this->NS_SCROLL_SECTION : $this->NS_SCROLL_CAT  );

            }

            /**
            * Display newsflash data
            * Too many mammeters to list.
            */ 
            function displayScroller (&$rows, 
                            $blogsc, $bblogcc, $gbblogsc,
                            $owner='yes',
                            $details='no',
                            $details_txt_title='Details...',  
                            $scroller_suffix='',
                            $scroller_cutoff=0) {

                global $database, $mainframe;
                //$rep_str      = array('<p>','<P>','</p>','</P>','<br />');  // ??
                $_ns_str      = '';
                $cnt          = 0;  
                $_output      = null;
                $new_image    = null;
                $image_width  = 50;
                $image_height = 50;
                $row_count    = 0;
		        $bg_image     = '';
                $clip_height  = ($this->NS_HEIGHT-2);
                $clip_width   = ($this->NS_WIDTH-2);
                $cell_height  = $this->NS_HEIGHT;
                $cell_width   = $this->NS_WIDTH+2;

				if($this->NS_USE_BG_IMAGE=='yes') {
                    if($this->NS_BG_IMAGE!="-1") {
					    $bg_image = "background: url(images/stories/". $this->NS_BG_IMAGE .") {$this->NS_BG_IMAGE_ALIGN} {$this->NS_BG_IMAGE_REPEAT};";
                    }
				}
                if($this->NS_CSS_OVERRIDE=='yes') {
                   // echo '<style>marquee a:link { color: #00FF00; }</style>';
                        // CSS output

                        $_output .=  "<div style=\"$bg_image position:relative; height:{$clip_height}px; width:{$clip_width}px; \">  <table class=\"moduletable{$scroller_suffix}\"   style=\"position:absolute; overflow:hidden; top:0px; left:0px;  height: {$cell_height}px; width:{$cell_width}px; \">
                        <tr>
                            <td class=\"moduletable{$scroller_suffix}\" style=\"position:absolute; overflow:hidden; top:0px; left:0px;  height:{$clip_height}px; width:{$clip_width}px; background: {$this->NS_BG_COLOR}; color: {$this->NS_TEXTCOLOR}; clip: rect(1px {$clip_width}px {$clip_height}px 1px);  \">
                                <marquee LOOP=\"infinite\" behavior=\"$this->NS_BEHAVIOR\" 
                                    direction=\"$this->NS_DIRECTION\"  
                                    height=\"{$clip_height}px\"
                                    width=\"{$clip_width}px\"
                                    scrollamount=$this->NS_AMOUNT
                                    scrolldelay=$this->NS_DELAY
                                    truespeed onmouseover=this.stop() onmouseout=this.start()  
                                    style=\"text-align: {$this->NS_TEXTALIGN} ; padding: {$this->NS_MARGIN}px; font-weight: $this->NS_TEXTWEIGHT; font-size: {$this->NS_TEXTSIZE}px;\" >"; 
                } else {
                        // non CSS output
                        $_output .=  "<div style=\"$bg_image position:relative; height:{$clip_height}px; width:{$clip_width}px; \">  <table class=\"moduletable$scroller_suffix\"   style=\"position:absolute; overflow:hidden;  height: {$cell_height}px; width:{$cell_width}px;  clip: rect(1px {$clip_width}px {$clip_height}px 1px);\">
                        <tr>
                            <td class=\"moduletable{$scroller_suffix}\" style=\"position:absolute; overflow:hidden; top:0px; left:0px;  height:{$clip_height}px; width:{$clip_width}px; text-align: {$this->NS_TEXTALIGN} ;\">
                                <marquee LOOP=\"infinite\" behavior=\"$this->NS_BEHAVIOR\" 
                                    direction=\"$this->NS_DIRECTION\"  
                                    height=\"{$clip_height}px\"
                                    width=\"{$clip_width}px\"
                                    scrollamount=$this->NS_AMOUNT
                                    scrolldelay=$this->NS_DELAY
                                    style=\"text-align: {$this->NS_TEXTALIGN} ; padding: {$this->NS_MARGIN}px; \"
                                    truespeed onmouseover=this.stop() onmouseout=this.start()>"; 
                }

                // load content
                $row1 = new mosContent( $database );
                // loop content
                $row_count=count($rows);
                foreach($rows as $row) {
                    // load row
                    $row1->load( $row );

                    // Owner - looks for the last item, in order to be 2nd to last
                    if((($cnt+1)==$row_count)&$this->NS_OWNER=='yes'&0) {
                        $_output .=  $this->displayOwner($owner);
                        // checks for left or right direction (horz. scrolling) and adjusts the format                       
                        if (($this->NS_DIRECTION=='left') || ($this->NS_DIRECTION=='right')) {
                            // adjust horizontal spacing
                            for($i=0;$i<$this->NS_SPACE_CHAR_TIMES;$i++) {
                                $_output .=  $this->NS_SPACE_CHAR;
                            }
                        } else { // normal operation (vert. scrolling)
                            // adjust vertical spacing
                            for($i=0;$i<$this->NS_LINE_CHAR_TIMES;$i++) {
                            $_output .=  $this->NS_LINE_CHAR;
                            }                            
                        }
                    }
                    if($this->NS_STRIP_HTML=='yes') {
                        // strip unwanted html tags - NFSP will handle formatting.
                        $row1->introtext = preg_replace("'<[\/\!]*?[^<>]*?>'is",'',$row1->introtext); 
                        //echo htmlentities($row1->introtext);
                    }
                    $image = null;
                    // get image information from images column
                    $image = explode('|',$row1->images);  

                    // re-assign defaults
                    $image_width  = 50;
                    $image_height = 50;

                    // if not cutoff and user wants to display image...
                    if(($this->NS_RETAIN_IMAGES=='yes')&&($this->NS_CUTOFF==0)) {
                        // is the image path empty?
                        if(!empty($image[0])) {
                            // get image info...assumes there will be results.
                            $image_info=@getimagesize("images/stories/{$image[0]}");
                            // check array $image_info
                            if(!empty($image_info)) {
                                // adjust percent
                                if(abs($this->NS_IMAGE_WIDTH)>100) {$image_width = 50;}
                                // get width multiplier - 
                                $image_width=($image_width/100);
                                // re-assign image size (in pixels)
                                $image_width=@$image_info[0]*$image_width;

                                // adjust percent		
                                if(abs($this->NS_IMAGE_HEIGHT)>100) {$image_height = 50;}
                                // get height multiplier - 
                                $image_height=($image_height/100);
                                // re-assign image size (in pixels)
                                $image_height=($image_info[1]*$image_height);
				
                            }
                            //echo "\$image_width=$image_width<br />";
                            //echo "\$image_height=$image_height<br />";

                            if(!(is_numeric($image[3]) || $image[3]=='')) { $image[3]=0; }
                            
                                
                                if((int)$image_width>=(int)$clip_width) {
                                    // adjust image width
                                    $image_width=((int)$clip_width/2);
                                } 
				
                                if((int)$image_height>=(int)$clip_height) { 
                                    // adjust image height
                                    $image_height=((int)$clip_height/2); 
                                }
				            //echo "Border =".$image[3].'<br />';
                             // asign image parameters                          
                            $new_image = "<div><img src=\"images/stories/{$image[0]}\" alt=\"{$image[2]}\" style=\"float: {$image[1]}; height: {$image_height}px; margin: 3px; width: {$image_width}px; border: {$image[3]}px #000 solid;\"></div>";
                        }

                    } 
                    // replace with image info or null
                    $row1->introtext = preg_replace("#{mos*.*?}#is","$new_image",$row1->introtext); 
                    // cut off text
                    if($scroller_cutoff>0) {
                        //$row1->introtext = @substr($row1->introtext,0,$scroller_cutoff);


                        //bugfix - $row1->introtext = @substr($row1->introtext,0,$scroller_cutoff);
                        if (strlen($row1->introtext) > $scroller_cutoff) {
                            $temp_string = @wordwrap($row1->introtext,$scroller_cutoff,"||");
                            $temp_string = explode("||", $temp_string);
                            $row1->introtext = $temp_string[0]. ' ';
                            $row1->introtext .= '...';
                        }
                        //end bugfix

                    }
                    // -------Get Itemid------------ 
                    $item_id = $mainframe->getItemid( $row1->id, 0, 0, $blogsc, $bblogcc, $gbblogsc );


                    // adjust Itemid if needed.
                    if(!$item_id) { $item_id=1; }
                        // titles
                        switch($this->NS_TITLES) {
                            case 'linked': ;
                            case 'linkall': 
                                $link = "index.php?option=com_content&amp;task=view&amp;id=". $row1->id ."&amp;Itemid=". $item_id;
                                $_output .=  "<a href=\"" . sefRelToAbs($link) ." \" title=\" {$row1->title} \"
                                    onmouseover=\"self.status='". addslashes($row1->title) ."'; return true;\" 
                                    onmouseout=\"self.status=' '; return true;\" 
                                    ><span style=\"font-weight: $this->NS_TITLEWEIGHT; font-size: {$this->NS_TITLESIZE}px; font-style: {$this->NS_TITLESTYLE};\">$row1->title</span></a> ";
                                break;
                            case 'nonlinked': $_output .=   "<span style=\"font-weight: $this->NS_TITLEWEIGHT; font-size: {$this->NS_TITLESIZE}px; font-style: {$this->NS_TITLESTYLE};\">".$row1->title.$this->NS_SPACE_CHAR."</span>";
                                break;
                            case 'notitlelinked': 
                                break;
                            case 'notitlenocontentlinked': 
                                if($this->NS_CSS_OVERRIDE=='yes') {
                                 $_output .=  "<span style=\"font-weight: $this->NS_TITLEWEIGHT; font-size: {$this->NS_TITLESIZE}px; font-style: {$this->NS_TITLESTYLE};\">$row1->title</span> ";
                                } else {  $_output .=  $row1->title;}   
                                break;
                            case 'no': 
                                break;
                            default : 
                                $link = "index.php?option=com_content&amp;task=view&amp;id=". $row1->id ."&amp;Itemid=". $item_id;
                                $_output .=  "<a href=\"" . sefRelToAbs($link) ."\" title=\" {$row1->title} \"
                                    onmouseover=\"self.status='". addslashes($row1->title) ."'; return true;\" 
                                    onmouseout=\"self.status=' '; return true;\" 
                                    ><span style=\"font-weight: $this->NS_TITLEWEIGHT; font-size: {$this->NS_TITLESIZE}px; font-style: {$this->NS_TITLESTYLE};\">$row1->title</span></a>"; 
                            break;
                        }
                        // text
                        switch($this->NS_TITLES) {
                            case 'linkall': ;
                            case 'nonlinked': ;
                            case 'notitlelinked': ;
                                $link = "index.php?option=com_content&amp;task=view&amp;id=". $row1->id ."&amp;Itemid=". $item_id;
                                //$row1->introtext = str_replace($rep_str,"",$row1->introtext); 
                                $_output .=  "<a href=\"" . sefRelToAbs($link) ."\" title=\" {$row1->title} \"
                                    onmouseover=\"self.status='". addslashes($row1->title) ."'; return true;\" 
                                    onmouseout=\"self.status=' '; return true;\" 
                                    >". $row1->introtext ."</a>";
                                break;
                            case 'linktitle': ;
                                break;
                            default : 
                                //$row1->introtext = str_replace($rep_str,"",$row1->introtext); 
                                $_output .=  $row1->introtext;
                                break;
                        }

                    // create details link
                    if($details=='yes') {
                        $det_text = $details_txt_title;
                        $_output .=  $this->NS_SPACE_CHAR;
                        $link = "index.php?option=com_content&amp;task=view&amp;id=". $row1->id ."&amp;Itemid=". $item_id;
                        $_output .=  " <a href=\"" . sefRelToAbs($link) ."\" title=\" {$row1->title} \"
                            onmouseover=\"self.status='". addslashes($row1->title) ."'; return true;\" 
                            onmouseout=\"self.status=' '; return true;\" 
                            >$det_text...</a> ";
                    }
                    // adjust space for horizontal scrolling
                    if (($this->NS_DIRECTION=='left') || ($this->NS_DIRECTION=='right')) {
                        for($i=0;$i<$this->NS_SPACE_CHAR_TIMES;$i++) {
                            $_output .=  $this->NS_SPACE_CHAR;
                        }
                    } else {
                        // adjust space for vertical scrolling
                        for($i=0;$i<$this->NS_LINE_CHAR_TIMES;$i++) {
                            $_output .=  $this->NS_LINE_CHAR;
                        }                            
                    }
  
                $cnt++;  
            }
            echo $_output;
            echo "    </marquee>
                    </td>
                </tr>
            </table></div><!-- Webraydian.com NFSP v{$this->nfsp_version} -->";
        } // end displayScroller

        /**
        * Displays the return link to owner
        */ 
         function displayOwner($owner) {
            if($owner == 'yes') {
                return "";// <a href='{$this->nfs_array['SITE']}' title=' {$this->nfs_array['TITLE']} ' target='_blank'>{$this->nfs_array['LINK_TITLE']}</a> ";
            }
        } // end displayOwner

        /**
        * Returns a mammeter value to an actual DB query element ASC/DESC
        */ 
        function returnSortType($type) {
            $change_type='';
            switch($type) {
                case strncmp($type,$this->sort_asc,3):  $change_type='ASC'; break;
                case strncmp($type,$this->sort_desc,3): $change_type='DESC'; break;
                case strncmp($type,$this->sort_mpop,3): $change_type='DESC'; break;
                case strncmp($type,$this->sort_lpop,3): $change_type='ASC'; break;
                default: $change_type='ASC'; break;
            }
            return $change_type;
        } // end returnSortType

       } // end class ns_Scroller
     } // end Define _SCROLLER

// ----------------------------- helper functions -----------------------------------

        /**
        * Helper DB function
        */
if(!defined('_SCROLLER_SUB')) {
    define('_SCROLLER_SUB',1);

    function getNewsFlash( $database, $limit=0, $cat_sect='cat', $how=null, $catid='0', $order='asc' ) {
        global $my, $mosConfig_offset;
        if($limit>0) {
            $limit = "LIMIT $limit";
        } else {
            $limit = "";
        }
        $now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
        if($cat_sect=='sect') {
            $query="SELECT a.id" // sections
                 ."\n FROM #__content AS a"
                 ."\n INNER JOIN #__categories AS b ON b.id = a.sectionid"
                 ."\n WHERE a.state = 1"
                 ."\n AND a.access  <= ". $my->gid .""
                 ."\n AND (a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."') "
                 ."\n AND (a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."')"
                 ."\n AND sectionid IN(". $catid .") ";
        } else {
            $query="SELECT a.id" // default - categories
                 ."\n FROM #__content AS a"
                 ."\n INNER JOIN #__categories AS b ON b.id = a.catid"
                 ."\n WHERE a.state = 1"
                 ."\n AND a.access  <= ". $my->gid .""
                 ."\n AND (a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."') "
                 ."\n AND (a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."')"
                 ."\n AND catid IN(". $catid .") ";
        }
         switch($how) {
            case 'random': 
                    $query .= "\n ORDER BY RAND() $limit"; // random
                break;
            case 'pop': 
                    $query .= "\n ORDER BY a.hits $order $limit"; // popular
                break;
            case 'new': 
                    $query .= "\n ORDER BY a.created $order $limit";  // newest / oldest
                break;
            default: 
                    $query .= "\n ORDER BY a.ordering $order $limit"; // ordered
            break;
        }
        //echo $query;
        $database->setQuery( $query );
        $rows = $database->loadResultArray();
        return $rows;
    } // end getNewsFlash
} // end Define _SCROLLER_SUB


// start of NS Script
$params =& new mosParameters( $module->params );
$NS_MAMMETER=& new ns_Scroller($params);


/**
* Load News
**/ 
if($NS_MAMMETER->NS_SORT_METHOD == $NS_MAMMETER->sort_rand) {
   $rows = getNewsFlash( $database, 
                         $NS_MAMMETER->NS_COUNT, 
                         $NS_MAMMETER->NS_CATSECT,
                         'random', 
                         $NS_MAMMETER->NS_SCROLL_SECTION, 
                         $NS_MAMMETER->returnSortType($NS_MAMMETER->NS_SORT_METHOD) );
} elseif( ($NS_MAMMETER->NS_SORT_METHOD == $NS_MAMMETER->sort_mpop) || ($NS_MAMMETER->NS_SORT_METHOD == $NS_MAMMETER->sort_lpop) ) { 
   $rows = getNewsFlash( $database, 
                         $NS_MAMMETER->NS_COUNT, 
                         $NS_MAMMETER->NS_CATSECT,
                         'pop', 
                         $NS_MAMMETER->NS_SCROLL_SECTION, 
                         $NS_MAMMETER->returnSortType($NS_MAMMETER->NS_SORT_METHOD) );
} elseif( ($NS_MAMMETER->NS_SORT_METHOD == $NS_MAMMETER->sort_newest) || ($NS_MAMMETER->NS_SORT_METHOD == $NS_MAMMETER->sort_oldest) ) { 
   $rows = getNewsFlash( $database, 
                         $NS_MAMMETER->NS_COUNT,
                         $NS_MAMMETER->NS_CATSECT, 
                         'new', 
                         $NS_MAMMETER->NS_SCROLL_SECTION, 
                         $NS_MAMMETER->returnSortType($NS_MAMMETER->NS_SORT_METHOD) );
} else {
   $rows = getNewsFlash( $database, 
                         $NS_MAMMETER->NS_COUNT,
                         $NS_MAMMETER->NS_CATSECT, 
                         '', 
                         $NS_MAMMETER->NS_SCROLL_SECTION, 
                         $NS_MAMMETER->returnSortType($NS_MAMMETER->NS_SORT_METHOD) ); 
}

/**
* Display News Scroller
**/ 

$NS_MAMMETER->displayScroller($rows, 
                              $blogsc, $bblogcc, $gbblogsc,
                              //$NS_MAMMETER->NS_COUNT,
                              $NS_MAMMETER->NS_OWNER,
                              $NS_MAMMETER->NS_DETAILS,
                             // $NS_MAMMETER->NS_DETAILS_TEXT,
                              $NS_MAMMETER->NS_DETAILS_TITLE,
                              $NS_MAMMETER->NS_SFX,
                              $NS_MAMMETER->NS_CUTOFF);

/**
* end NewsFlash Scroller Pro 3.3
**/ 





?>